<%-- 
    Document   : add_product
    Created on : 14.04.2013, 14:31:08
    Author     : Yasya
--%>
<%@page import="javax.naming.NamingException"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="delta.productcatalog.controller.CategoryFacadeRemote"%>
<%@page import="delta.productcatalog.model.Category"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%!    private CategoryFacadeRemote categoryFacade;

    public void jspInit() {
        try {
            InitialContext ic = new InitialContext();
            categoryFacade = (CategoryFacadeRemote) ic.lookup(
                    "java:global/ProductCatalog/ProductCatalog-ejb/CategoryFacade!delta.productcatalog.controller.CategoryFacadeRemote");

        } catch (NamingException ex) {
            ex.printStackTrace();
        }
    }
%>


<!DOCTYPE html>
<html>
    <head>
        <script src="scripts/productValidator.js"></script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="css/styl_product.css">
        <title>Add/Edit product</title>
    </head>
    <body>      
        <header>
            <div id ="top_name"> <h1> Product</h1> </div>
        </header>
        <div id="main">
            <div id="label">
                <p>Name:</p>
                <p>Category:</p>
                <p>Price:</p>
                <p>Picture:</p>
                <p>Description:</p>
            </div>
            <div id="add_product">  
                <form id="product_form" method="Get" action="AddProduct"> 
                    <p> <input 
                            id="name_input" 
                            type="text" 
                            name="name" 
                            size="50"
                            oninput="validateName()" />
                        <span id="name_error"> Name should not be empty</span>
                        <span id="name_length_error" style="display:none"> Name is too long</span>


                    </p>
                    <p> <select  name="category" size = 1> 

                            <%for (Category c : categoryFacade.findAll()) {%>
                            <option value=<%=c.getId_category()%> > <%= c.getName()%></option>
                            <%}%>


                        </select> </p>
                    <p>   <input
                            id="price_input" 
                            type="text" 
                            name="price" 
                            size="50"
                            oninput="validatePrice()"/>
                        <span id="price_error"> Price should not be empty</span>
                        <span id="price_number_error" style="display:none"> Illegal value</span>
                    </p>
                    <p>  <input type="text" name="picture" size="50" /></p>
                    <p>  <textarea name="description" cols="39" rows="7"></textarea></p>
                    

                </form>
                            <button 
                        id="ok"  
                        onclick="submitForm()">
                        Ok
                    </button><br>
                <button id="func" onclick="window.location.href='index.jsp' ">Cancel</button> 
            </div>
        </div>
    </body>
</html>